<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ page import="ihis.model.*"%>
<%@ page import="ihis.core.*"%>
<%@ page import="java.util.*"%>
<%@ page import="java.text.SimpleDateFormat"%>
<%@page import="ihis.tms.client.IHISTMSClient"%>

<%
	IHISTMSClient tms = new IHISTMSClient();
	IHISCore core = new IHISCore();

	// variables
	String startDate = "";
	String endDate = "";
	String reportDate = "";
	String periodType = "";
	String user = "";
	String project = "";
	String team = "";
	String userName = "";
	String teamName = "";
	String projectName = "";
	String ownerType = "";

	// read request(filter)
	startDate = request.getParameter("startDate") != null ? request
			.getParameter("startDate") : "";
	endDate = request.getParameter("endDate") != null ? request
			.getParameter("endDate") : "";
	System.out.println("SearchSchedule.PeriodType : " + request.getParameter("periodType"));
	periodType = request.getParameter("periodType") != null ? request
			.getParameter("periodType") : ""
			+ IHISConstants.TIME_UNIT_WEEKLY;
	System.out.println("SearchSchedule.PeriodType after: " + periodType);
	ownerType = request.getParameter("ownerType") != null ? request
			.getParameter("ownerType") : ""
			+ IHISConstants.OWNERTYPE_PERSON;
	if (request.getParameter("firstLoad") != null) {
		user = (String) session.getAttribute("loginId");
		if (IHISUtil.isEmpty(user)) {
			user = request.getParameter("loginId");
		}
	} else {
		user = request.getParameter("user") == null
				|| "0".equals(request.getParameter("user")) ? ""
				: request.getParameter("user");
	}
	project = request.getParameter("project") == null
			|| "0".equals(request.getParameter("project")) ? ""
			: request.getParameter("project");
	team = request.getParameter("team") == null
			|| "0".equals(request.getParameter("team")) ? "" : request
			.getParameter("team");
	userName = IHISUtil.nullCheck(tms.getUserName(user), "No body");
	teamName = IHISUtil.nullCheck(tms.getTeamName(team));
	projectName = IHISUtil.nullCheck(tms.getProjectName(project));

	// initiate filter
	GeneralFilter filter = new GeneralFilter();
	filter.setPeriodType(Integer.parseInt(periodType));
	filter.setUserId(user);
	filter.setProjectId(project);
	filter.setTeamId(team);
	filter.setOwnerType(Integer.parseInt(ownerType));

	SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
	if (!IHISUtil.isEmpty(startDate)) {
		filter.setStartDate(sdf.parse(startDate));
	}
	if (!IHISUtil.isEmpty(endDate)) {
		filter.setEndDate(sdf.parse(endDate));
	}
	if (!IHISUtil.isEmpty(reportDate)) {
		filter.setReportDate(reportDate);
	}else{
		Date reportDat = null;
		if (!IHISUtil.isEmpty(startDate)) {
			reportDat = sdf.parse(startDate);
		}else if (!IHISUtil.isEmpty(endDate)) {
			reportDat = sdf.parse(endDate);
		}else{
			reportDat = new Date(System.currentTimeMillis());
		}
		sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		filter.setReportDate(sdf.format(GeneralFilter.generateToDate(reportDat, filter.getPeriodType(), false)));
		reportDate = filter.getReportDate();
	}
	System.out.println("FILTER : " + filter.toString() + request.getParameter("periodType") + " /" + periodType);
%>